﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls; 
using System.IO;
using BUS;
using DAO;

namespace OnlineDigitalCameraWebsite.Admin
{
    public partial class LensList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            { 
                LoadDS(); 
            }
        } 

        private void LoadDS()
        {
            LensBUS cBUS = new LensBUS();
            List<Lens> list = new List<Lens>();
            list = cBUS.GetListAll_Sort();
            gvDS.DataSource = list;
            gvDS.DataBind();

        }  
        protected void btnOK_Click(object sender, EventArgs e)
        {
            
        }
        protected void btnThem_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/Admin/LensList_Detail.aspx?type=them&id=0");
        }
        protected void gvDS_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gvDS.PageIndex = e.NewPageIndex;
            LoadDS();
        }

        protected void gvDS_RowEditing(object sender, GridViewEditEventArgs e)
        {
            gvDS.EditIndex = e.NewEditIndex;
            LoadDS();
        }

        protected void gvDS_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            gvDS.EditIndex = -1;
            LoadDS();
        }

        protected void gvDS_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
        { 
        }
        public void ShowMessage(string Content)
        {
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script language='javascript'>alert('" + Content + "');</script>");
        }
        protected void gvDS_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void gvDS_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            Label lb1 = (Label)gvDS.Rows[e.RowIndex].FindControl("id1");
            int ma = Convert.ToInt32(lb1.Text);
            AccessoriesBUS cBUS = new AccessoriesBUS();
            if (cBUS.Delete(ma))
            {
                lbThongBao.Text = "Xóa Lens thành công! ";
                LoadDS();
            }
            else
            {
                lbThongBao.Text = "Xóa Lens thất bại !";
            }

        }
         
    }
}